package com.itcat.cn.web;

import com.itcat.cn.pojo.Brand;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@WebServlet("/servletDemo1")
public class ServletDemo1 extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1，读取数据
        List<Brand> brands = new ArrayList();
        brands.add(new Brand(1, "三只松鼠", "三只松鼠", 100, "三只松鼠,好吃不上火", 1));
        brands.add(new Brand(2, "三只松鼠", "三只松鼠", 100, "三只松鼠,好吃不上火", 1));
        brands.add(new Brand(3, "三只松鼠", "三只松鼠", 100, "三只松鼠,好吃不上火", 1));

        //2.存取到request域中
        request.setAttribute("brands",brands);
        request.setAttribute("status",1);

        //3，转发到El.js中
        //request.getRequestDispatcher("/el.jsp").forward(request,response);
        request.getRequestDispatcher("/jstl.jsp").forward(request,response);

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
